/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itsc.ds2.bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.itsc.ds2.dao.DiscsDaoLocal;
import mx.itsc.ds2.enumerations.TransactionStatus;
import mx.itsc.ds2.model.Discs;

/**
 *
 * @author Eli
 */
@Stateless
public class DiscBl implements DiscBlLocal {
    @EJB
    private DiscsDaoLocal discsDao;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
    public TransactionStatus register(Discs disc) {
        if (discsDao.findByBarcode(disc)) {
            return TransactionStatus.INCOMPLETE;
        } else {
            discsDao.create(disc);
            return TransactionStatus.COMPLETE;
        }
    }

    @Override
    public TransactionStatus modify(Discs disc) {
           if (disc.getIdDisc() == null || discsDao.find(disc.getIdDisc()) == null) {
            return TransactionStatus.INCOMPLETE;
        } else {
            discsDao.edit(disc);
            return TransactionStatus.COMPLETE;
        }
    }

    @Override
    public TransactionStatus delete(Discs disc) {
           if (disc.getIdDisc() == null || discsDao.find(disc.getIdDisc()) == null) {
            return TransactionStatus.INCOMPLETE;
        } else {
            discsDao.remove(disc);
            return TransactionStatus.COMPLETE;
        } 
    }

    @Override
    public List<Discs> getAll() {
        return discsDao.findAll();
    }

    @Override
    public Discs findById(int disc) {
        return discsDao.find(disc);
    }

    
    
}
